package logic

import (
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserAddLogic) UserAdd(req *types.UserAddRquest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.UserRpc.NovelAdd(l.ctx, &userclient.NovelAddRequest{
		Title:  req.Title,
		Writer: req.Writer,
		Hot:    req.Hot,
		Image:  req.Image,
		Price:  float32(req.Price),
		Num:    req.Num,
	})
	if err != nil {
		return &types.Response{
			Mes:  err.Error(),
			Code: 400,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Mes:  "小说添加成功",
		Code: 200,
		Data: add,
	}, nil
}
